// ActionScript file


	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.events.CloseEvent;
	import mx.rpc.events.ResultEvent;
	

	private function onListar( event:ResultEvent ):void{
		dg.dataProvider = event.result as Object;
		bteditar.enabled = true;
		dg.enabled = true;
		btexcluir.enabled = true;
		btnovo.enabled = true;
		content.enabled = false;
		btcancelar.enabled = false;
		btsalvar.enabled = false;
		dg.selectedIndex = 0;
	}
	
	private function salvar():void{
		var a:ArrayCollection = new ArrayCollection();
		
		a.addItem( { 
	
			"id" : pn_id.text, 
			"banco" : pn_banco.selectedItem.data, 
			"agencia" : pn_agencia.text, 
			"conta" : pn_conta.text, 
			"cedente" : pn_cedente.text, 
			"carteira" : pn_carteira.selectedItem.data,  
			"convenio" : pn_convenio.text, 
			"codcedente" : pn_codcedente.text, 
			"instrucao" : pn_instrucao.text, 
			"demo" : pn_demo.text, 
			"cobrataxa" : pn_cobrataxa.selected.toString(), 
			"valortaxa" : pn_valortaxa.text, 
			"juntar" : pn_juntar.selected.toString(), 
			"tipojuros" : pn_tipojuros.selectedItem.data, 
			"pjuros" : pn_pjuros.selectedItem.data,  
			"vjuros" : pn_vjuros.text, 
			"juros" : pn_juros.selected.toString(), 
			"tipomulta" : pn_tipomulta.selectedItem.data, 
			"pmulta" : pn_pmulta.selectedItem.data, 
			"vmulta" : pn_vmulta.text, 
			"multa" : pn_multa.selected.toString(), 
			"boleto" : pn_boleto.selected.toString()

		} );
		Remote.salvar(a);
	}
	
	public function excluir():void{
		Alert.yesLabel='Sim';
		Alert.noLabel='Não';
		Alert.show('Deseja realmente excluir esse registro?','ATENÇÃO',Alert.YES|Alert.NO, null, excluirResult);
	}public function excluirResult(e:CloseEvent):void{
		if(e.detail == Alert.YES){
			Remote.excluir( pn_id.text );
		}
	}
	
	
	private function editar():void{
		dg.enabled = false;
		bteditar.enabled = false;
		btexcluir.enabled = false;
		btnovo.enabled = false;
		content.enabled = true;
		btcancelar.enabled = true;
		btsalvar.enabled = true;
	}
	
	private function cancelar():void{
		bteditar.enabled = true;
		dg.enabled = true;
		btexcluir.enabled = true;
		btnovo.enabled = true;
		content.enabled = false;
		btcancelar.enabled = false;
		btsalvar.enabled = false;
	}	
	
	private function novo():void{
		content.enabled = true;
		dg.enabled	=	false;
		btsalvar.enabled = true;
		btcancelar.enabled = true;
		resets();
	}
	
	
	private function resets():void{	
		pn_id.text	= 	null;
		pn_banco.selectedIndex	= 	0;
		pn_agencia.text	= 	null;
		pn_conta.text	= 	null;
		pn_cedente.text	= 	null;
		pn_carteira.selectedIndex	= 	0;
		pn_convenio.text	= 	null;
		pn_codcedente.text	= 	null;
		pn_instrucao.text	= 	null;
		pn_demo.text	= 	null;
		pn_cobrataxa.selected	= 	false;
		pn_valortaxa.text	= 	null;
		pn_juntar.selected	= 	false;
		pn_tipojuros.selectedIndex	= 	0;
		pn_pjuros.selectedIndex	= 	0;
		pn_vjuros.text	= 	null;
		pn_juros.selected	= 	false;
		pn_tipomulta.selectedIndex	= 	0;
		pn_pmulta.selectedIndex	= 	0;
		pn_vmulta.text	= 	null;
		pn_multa.selected	= 	false;
		pn_boleto.selected	= 	false;
 	}	
 	
 	
 	private function atualizarGrid():void{
 	//	selectComboBox( pn_carteira , dg.selectedItem.carteira , 'carteira' );
 	}
 	
 	
 	
 	
 	
 	
 	
 	